package com.ruoyi.web.controller.task;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TaskInfo;
import com.ruoyi.system.service.ITaskInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务信息Controller
 * 
 * @author ruoyi
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/task/info")
public class TaskInfoController extends BaseController
{
    @Autowired
    private ITaskInfoService taskInfoService;

    /**
     * 查询任务信息列表
     */
//    @PreAuthorize("@ss.hasPermi('task:info:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(TaskInfo taskInfo)
    {
        startPage();
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        return getDataTable(list);
    }

    /**
     * 导出任务信息列表
     */
//    @PreAuthorize("@ss.hasPermi('task:info:export')")
    @Anonymous
    @Log(title = "任务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskInfo taskInfo)
    {
        List<TaskInfo> list = taskInfoService.selectTaskInfoList(taskInfo);
        ExcelUtil<TaskInfo> util = new ExcelUtil<TaskInfo>(TaskInfo.class);
        util.exportExcel(response, list, "任务信息数据");
    }

    /**
     * 获取任务信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('task:info:query')")
    @Anonymous
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Integer taskId)
    {
        return success(taskInfoService.selectTaskInfoByTaskId(taskId));
    }

    /**
     * 新增任务信息
     */
//    @PreAuthorize("@ss.hasPermi('task:info:add')")
    @Anonymous
    @Log(title = "任务信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskInfo taskInfo)
    {
        return toAjax(taskInfoService.insertTaskInfo(taskInfo));
    }

    /**
     * 修改任务信息
     */
//    @PreAuthorize("@ss.hasPermi('task:info:edit')")
    @Anonymous
    @Log(title = "任务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskInfo taskInfo)
    {
        return toAjax(taskInfoService.updateTaskInfo(taskInfo));
    }

    /**
     * 删除任务信息
     */
//    @PreAuthorize("@ss.hasPermi('task:info:remove')")
    @Anonymous
    @Log(title = "任务信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Integer[] taskIds)
    {
        return toAjax(taskInfoService.deleteTaskInfoByTaskIds(taskIds));
    }
}
